/**
 *  *2010-8-9 下午04:31:14  add 
 */
package com.base.myproject.client.HR.batchpro;


import com.base.myproject.client.ui.BaseJDBCPanel;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.extjs.gxt.ui.client.widget.form.LabelField;
import com.extjs.gxt.ui.client.widget.form.TextArea;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * @author Administrator
 *2010-8-9
 * javazgw@gmail.com
 */
public class BatchPro extends BaseJDBCPanel{
	HorizontalPanel hpanel = new HorizontalPanel();
	LayoutContainer center  =new LayoutContainer();
	ComboBox<ProcItem> combo = new ComboBox<ProcItem>();  

	public BatchPro()
	{
		init();
	}
	public void init()
	{
		initwidgetx();
	}
	private void initwidgetx() {
		initTop();
		initCenter();
		
		VerticalPanel vpanel = new VerticalPanel();
		vpanel.add(hpanel);
		vpanel.add(center);
		add(vpanel);
		
	}

	void initTop()
	{
		
		 
		 ListStore<ProcItem> ProcItemstore = new ListStore<ProcItem>();  
		 
//		 ProcItemstore.add(new Healthproc_item("健康证"));
		 ProcItemstore.add(new Contractitem("合同"));
		 ProcItemstore.add(new BcodeLeave("员工离职"));
		 ProcItemstore.add(new ChangeBcodeValue("员工其他信息修改"));
		 
	    combo.setEmptyText("请选择批处理...");  
	    combo.setDisplayField("name");  
	    combo.setWidth(150);  
	    combo.setStore(ProcItemstore);  
	    combo.setTypeAhead(true);  
	    combo.setTriggerAction(TriggerAction.ALL);  
	    
	    combo.addListener(Events.Changed, getListener());
	    hpanel.add(new Label("请选择批处理类型:"));
	    hpanel.add(combo);
	    
	}
	void initCenter()
	{
		
	}
	
	
	int sync = 0;                                                      
	Listener<BaseEvent> defaultlistener;                               
                                                                     
	Listener<BaseEvent> getListener() {                                
		if(defaultlistener!=null)                                        
		{                                                                
			return defaultlistener;                                        
		}                                                                
                                                                     
		defaultlistener = new Listener<BaseEvent>() {                    
			public void handleEvent(BaseEvent be) {                        
				sync++;                                                      
				try {                                                        
					if (sync == 1) {                                           
						if (be.getType() == Events.Select) {                     
							if (be.getSource().equals( "")) {                            
                                                                     
							}                                                      
						} else if (be.getType() == Events.Changed) {              
							if (be.getSource().equals(combo)) {         
								center.removeAll();
								center.add(combo.getValue().initwidget())  ;    
								center.layout();
							}                                                      
						} else if (be.getType() == Events.KeyUp) {               
							if (be instanceof ComponentEvent) {                    
								if (((ComponentEvent) be).getKeyCode() == 13) // 回车
								{                                                    
								}                                                    
							}                                                      
						}                                                        
					}                                                          
				} finally {                                                  
					sync--;                                                    
				}                                                            
			}                                                              
                                                                     
		};                                                               
		return defaultlistener;                                          
	}        
	
	
}
